function ShowCountDown(starttime,endtime,ele,t){
    var endDate = new Date(endtime);
    var now = new Date();
    var tip = $(ele).find('.tip');
    var cc = $(ele).find('.time');

    if(starttime>now){
        tip.html('距活动开始');
        endDate = new Date(starttime);
    }
    if(starttime<=now && tip.html()=='距活动开始'){
        tip.html('距活动结束');
    }

    if(starttime<=now && endDate>=now){
        $('.splist-wrap').show();
    }

    if(endDate<=now){
        if(cc.html()!="")cc.html("");
        tip.html('活动已结束！');
        $('.splist-wrap').remove();
        clearInterval(t);
        return;
    }

    var leftTime=endDate.getTime()-now.getTime();
    var leftsecond = parseInt(leftTime/1000);
    var day1=Math.floor(leftsecond/(60*60*24));
    var hour=Math.floor((leftsecond-day1*24*60*60)/3600);
    var minute=Math.floor((leftsecond-day1*24*60*60-hour*3600)/60);
    var second=Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60);
    cc.html("<span>"+day1+"</span>天<span>"+hour+"</span>小时<span>"+minute+"</span>分<span>"+second+"</span>秒");
}

$('.activity').each(function(index,ele) {
    var starttime = parseInt($(this).attr('data-starttime'));
    var endtime = parseInt($(this).attr('data-endtime'));
    ShowCountDown(starttime,endtime,ele);
    var _t = setInterval(function(){ShowCountDown(starttime,endtime,ele,_t)},1000);
});